package com.example.onlineeducation.repository

import com.example.onlineeducation.data.entity.BannerEntity
import com.example.onlineeducation.data.entity.NoticeEntity
import com.example.onlineeducation.mapper.BannerMapper
import com.example.onlineeducation.mapper.NoticeMapper
import com.example.onlineeducation.net.ApiService
import com.yc.jetpacklib.base.YcRepository
import com.yc.jetpacklib.extension.ycFlow
import com.yc.jetpacklib.net.YcResult
import kotlinx.coroutines.flow.Flow

/**
 * SimpleDes:
 * Creator: Sindi
 * Date: 2021-06-30
 * UseDes:首页
 */
class MainHomeRepository(private val apiService: ApiService) : YcRepository() {

    /**
     *  首页轮播图
     */
    private val mBannerMapper by lazy {
        BannerMapper()
    }
    fun getBanner(projectId :String) : Flow<YcResult<List<BannerEntity>?>>  = ycFlow{
        val json = apiService.getBanner(projectId)
        send(YcResult.Success(mBannerMapper.map(json.dataList)))
    }


    /**
     *  首页公告栏
     */
    private val mNoticeMapper by lazy {
        NoticeMapper()
    }
    fun getNotice(projectId :String) : Flow<YcResult<List<NoticeEntity>?>>  = ycFlow{
        val json = apiService.getNotice(projectId)
        send(YcResult.Success(mNoticeMapper.map(json.dataList)))
    }
}